from day01.basecla import BaseClass
from day01.basecla import driver
from selenium.webdriver.common.by import By
from time import sleep
import random
c=BaseClass()
c.open_browser('file:///E:/%E8%93%AC%E8%8E%B1%E5%B0%8F%E8%AF%BE2024%E6%B5%8B%E8%AF%95/%E7%AC%AC%E5%9B%9B%E9%98%B6%E6%AE%B5/Selenium%E8%87%AA%E5%8A%A8%E5%8C%96/selenium_demo/day04demo/demo02.html')
locator=[By.ID,By.NAME,By.CLASS_NAME,By.XPATH,By.CSS_SELECTOR]
mymale=driver.find_element(locator[0],'male')
myfemale=driver.find_element(locator[0],'female')
t1=driver.find_element(locator[0],'t1')
if mymale.is_selected()==True:
    str1=mymale.get_attribute('value')
else:
    str1=myfemale.get_attribute('value')
t1.send_keys(str1)
sleep(2)
myfemale.click()
str1=myfemale.get_attribute('value')
t1.clear()
t1.send_keys('我是',str1,'生')
sleep(2)
#最喜欢的出行方式
style=driver.find_elements(locator[1],'t1')
#style=driver.find_elements(locator[3],'//*[@name=t1]')
t2=driver.find_element(locator[4],'#t2')
#随机出行方式(1-4的随机整数)
r=random.randint(1,4)
print(r)
for i in style:
    #print(i)
    if str(r)==i.get_attribute("value"):
        i.click()
#喜欢的图书类型
hobby1=driver.find_element(locator[3],'//*[@id="a1"]')
hobby2=driver.find_element(locator[3],'//*[@id="a2"]')
hobby3=driver.find_element(locator[3],'//*[@id="a3"]')
hobby4=driver.find_element(locator[3],'//*[@id="a4"]')
t3=driver.find_element(locator[4],'#t3')
hobby1.click()
hobby2.click()
hobby3.click()
hobby4.click()
#print(hobby1.text)

t3.send_keys(11)
#driver.quit()
